package com.henu.ocr.api.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DataDistributionResponseModel {
    @Builder.Default
    private String success = "false";
    private String message;
    private HashMap<String, String> mdMappings;

    //    private String mdmCode;
//    private String entityCode;
//    private String busiDataId;
    public DataDistributionResponseModel(String message, String mdmCode, String entityCode, String busiDataId) {
        this.message = message;
        this.mdMappings = new HashMap<>();
        this.mdMappings.put("mdmCode", mdmCode);
        this.mdMappings.put("entityCode", entityCode);
        this.mdMappings.put("busiDataId", busiDataId);
    }

    public DataDistributionResponseModel(String isSuccess, String message, String mdmCode, String entityCode, String busiDataId) {
        this(message, mdmCode, entityCode, busiDataId);
        this.success = isSuccess;
    }

    public static DataDistributionResponseModel Exception(Exception e, DataDistributionRequestModel model) {
        return builder().message("主数据分发失败," + e.getMessage()).mdMappings(new HashMap<String, String>() {
            {
                put("mdmCode", model.get("mdm_code"));
                put("entityCode", model.getMdType());
            }
        }).build();
    }
    public static DataDistributionResponseModel Ok( DataDistributionRequestModel model, String busiDataId) {
        return new DataDistributionResponseModel("true", "主数据分发成功", model.get("mdm_code"), model.getMdType(), busiDataId);
    }
    public static DataDistributionResponseModel Fail( DataDistributionRequestModel model) {
        return new DataDistributionResponseModel("主数据分发失败", model.get("mdm_code"), model.getMdType(), null);
    }
}